<template>
  <div class="index">
    <div class="tops">
      <!-- <router-link to="/login">12</router-link> -->
      <section
        class="wmassageMask"
        v-show="writeMessageShow"
        @click="writeMessageFun($event)"
      >
        <div class="messageMaskContent" ref="msk">
          <p>填写段位</p>
          <div class="duanwei">
            <div class="sel" style="height:5rem;overflow:hidden"> 
              <select v-model="duanw" name="段位" size="5" style="height:4.5rem;text-align: center;" >
                <option
                  v-for="(item, index) in xduanwei"
                  :key="index"
                  :value="item.id"
                >
                  {{ item.level }}
                </option>
              </select>
            </div>

            <div style="margin-top: 1rem">
              <button class="submits" @click="sub()">完成</button>
            </div>
          </div>
        </div>
      </section>
    </div>
    <div class="header">
      <div class="header1">
        <div class="head">
          <span class="span1">{{ main.position }}</span>
          <span class="span2" @click="writeMessageShow = true">{{
            main.level
          }}</span>
          <img :src="main.filepath" alt="touxiang" class="imgs" />
        </div>
        <span class="name">{{ main.name }}</span>
      </div>
      <div class="idea">
        <p>教学理念：{{ main.title }}</p>
        <span @click="edit;">编辑</span>
      </div>
    </div>
    <div class="main">
      <p class="tit tits">
        个人信息 <span style="color: #999" @click="edit">编辑个人信息</span>
      </p>
      <div class="mains">
        <div class="list">
          <span>姓名</span> <span>{{ main.name }}</span>
        </div>
        <div class="list">
          <span>性别</span> <span>{{ main["sex"] == 1 ? "男" : "女" }}</span>
        </div>
        <div class="list">
          <span>学科</span> <span>{{ main.projects }}</span>
        </div>
        <div class="list">
          <span>教学年限</span> <span>{{ main.teach_year }}年</span>
        </div>
        <div class="list">
          <span>当前课酬等级</span> <span>{{ main.price }}</span>
        </div>
      </div>
    </div>
    <router-link to="/login">1</router-link>
    <div class="main2">
      <p class="tit">自我介绍</p>
      <textarea
        name=""
        cols="30"
        rows="10"
        class="text"
        maxlength="100"
        @input="descInput"
        v-model="desc"
      ></textarea>

      <p><button class="preservation" @click="preservation">保存</button></p>
      <span class="daos">{{ remnant }}</span>
    </div>
    <div class="footer">
      <div class="index" @click="index()">
        <img src="../assets/index.png" alt="" />
        <p>首页</p>
      </div>
      <div @click="phb()">
        <img src="../assets/wpaihang.png" alt="" />
        <p>排行榜</p>
      </div>
      <div>
        <img src="../assets/xmy.png" alt="" />
        <p style="color: #d8393e">个人中心</p>
      </div>
    </div>
  </div>
</template>
<style scoped>
.submits {
  width: 5rem;
  border: none;
  color: #fff;
  background: #00b7ee;
  margin-top: 1rem;
  padding: 0.5rem 0;
  border-radius: 0.5rem;
  margin: 0 auto;
  display: block;
}
.wmassageMask {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  background-color: rgba(0, 0, 0, 0.3);
  z-index: 101;
}
.messageMaskContent {
  position: absolute;
  bottom: 30%;
  left: 15%;
  width: 100%;
  background-color: #fff;
  width: 70%;
  border-radius: 1rem;
  height: 15rem;
}
.messageMaskContent p {
  text-align: center;
  color: #fff;
  background: #4769ef;
  padding: 2rem 0 3rem 0;
  width: 100%;
  border-radius: 0.5rem;
}
.duanwei select {
  width: 80%;
  border: 1px solid #d5d5d5;
  margin-left: 10%;
  border-radius: 0.5rem;
  height: 2rem;margin-top: 0.5rem;
}
.duanwei {
  
  width: 80%;
  margin: -2rem auto;
  background-color: #fff;
  padding:0.5rem 0 0.5rem 0;
}

.tits {
  display: flex;
  justify-content: space-between;
}
.tits span {
  text-align: left;
  width: 8rem;
}
.tops {
  background-color: #d62c32;
  height: 10rem;
}
.header {
  width: 90%;
  margin: 0 auto;
  border-radius: 1rem;
  background-color: #fff;
  padding: 0 0 2rem 0;
  margin-top: -3rem;
  box-shadow: #ccc 2px 2px 2px;
}
.head {
  height: 2.5rem;
  position: relative;
}
.head .imgs {
  display: block;
  margin: 0 auto;
  position: relative;
  top: -2.5rem;
  background-color: #fff;
  border-radius: 4rem;
  padding: 0.3rem;
  width: 4rem;
  height: 4rem;
}
.head img {
  width: 4rem;
}
.name {
  text-align: center;
  display: block;
  font-size: 0.9rem;
  color: #999;
}
.head .span1 {
  border: 1px solid #ccc;
  background: #b5b5b5;
  color: #fff;
  font-size: 0.5rem;
  padding: 0 2px;
  border-radius: 4px;
  position: absolute;
  left: 4rem;
  top: 5px;
}
.head .span2 {
  border: 1px solid #ccc;
  background: #f9a519;
  color: #fff;
  font-size: 0.5rem;
  padding: 0 2px;
  border-radius: 4px;
  position: absolute;
  right: 3rem;
  top: 10px;
}
.idea {
  position: relative;
}
.idea p {
  width: 80%;
  margin: 0 auto;
  color: #999;
  font-size: 0.9rem;
  padding: 0.5rem 0;
}
.idea span {
  color: #fff;
  background: #84ccc9;
  font-size: 0.8rem;
  padding: 0 0.6rem;
  position: absolute;
  right: 2rem;
  top: 0.5rem;
  border-radius: 0.2rem;
}
.main,
.main2 {
  width: 90%;
  margin: 0 auto;
  margin-top: 2rem;
  border-radius: 1rem;
  border-top: 0px;
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12), 0 0 6px 0 rgba(0, 0, 0, 0.04);
  outline: none;
  padding-top: 1rem;
}
.tit {
  border-left: 0.3rem solid #d62c32;
  text-indent: 1rem;
  padding: 0 0 0.5rem 0;
}

.mains .list {
  display: flex;
  justify-content: space-between;
  width: 95%;
  margin: 0 auto;
  border-bottom: 1px solid #f7f7f7;
  padding: 1rem 0;
  color: #909090;
  font-size: 0.9rem;
}
.text {
  width: 90%;
  margin: 0 auto;
  display: block;
  border: none;
  outline: none;
}
.main2 {
  position: relative;
  margin-bottom: 4rem;
  padding: 2rem 0;
}
.main2 .daos {
  color: #ccc;
  position: absolute;
  right: 1rem;
  bottom: 1rem;
}
.preservation {
  width: 10rem;
  color: #fff;
  background: #00b7ee;
  border: none;
  padding: 0.5rem 0;
  border-radius: 1rem;
  display: block;
  margin: 0 auto;
  outline: none;
}
.footer {
  display: flex;
  justify-content: space-around;
  font-size: 0.8rem;
  text-align: center;
  border-top: 1px solid #ccc;
  position: fixed;
  bottom: 0;
  width: 100%;
  background: #fff;
  padding: 5px 0;
}
.footer div {
  text-align: center;
}
.footer img {
  display: block;
  width: 2rem;
  margin: 0 auto;
}
</style>
<script>
import axios from "axios";
export default {
  data() {
    return {
      remnant: 100,
      main: "",
      desc: "",
      writeMessageShow: false,
      duanw: "1", //修改段位
      xduanwei: [],
    };
  },

  methods: {
    descInput() {
      var txtVal = this.desc.length;
      this.remnant = 100 - txtVal;
    },
    preservation() {
      let that = this;
      axios
        .post("/Teacontent/publish", {
          id: localStorage.getItem("ids"),
          content: that.desc,
        })
        .then((res) => console.log(res.data));
    },
    edit() {
      this.$router.push({ path: "/edit" });
    },
    phb() {
      this.$router.push({ path: "/Ranking" });
    },
    index() {
      this.$router.push("/");
    },
    writeMessageFun(ev) {
      if (!this.$refs.msk.contains(ev.target)) {
        this.writeMessageShow = false;
      }
    },
    sub() {
      let that = this;
      axios
        .post("/Levels/paragraph", {
          id: localStorage.getItem("ids"),
          level_id: that.duanw,
        })
        .then((res) => {
          console.log(res.data);
          location.reload();
        });
    },
  },
  created() {
    let that = this;
    axios
      .post("/Personal/index", { id: localStorage.getItem("ids") })
      .then((res) => {
        if (res.data.data.id === " ") {
          this.$router.push({ path: "/login" });
        } else {
          console.log(res.data.data);
          that.main = res.data.data;
          that.desc = res.data.data.content;
          // that.duanw = res.data.data.level;
        }
      });
    axios.get("/Levelquery/index").then((res) => {
      console.log(res.data), (that.xduanwei = res.data.level);
    });
    if(localStorage.getItem("ids")==null){
      this.$router.push("/login")
    }
  },
};
</script>


